
#ifndef E2PROM_H
#define E2PROM_H

#ifdef D_STM8_INNEREEPROM
#define EEP_SETTING_ADDRESS FLASH_DATA_START_PHYSICAL_ADDRESS
EXT volatile uchar _2ch_prm_EEP[N_AUDIO_ITEM] @(EEP_SETTING_ADDRESS);
EXT volatile uchar asp_setting_EEP[ASP_INDEX_NUM] @(EEP_SETTING_ADDRESS+N_AUDIO_ITEM);
#define EEP_ASP_ADDRESS EEP_SETTING_ADDRESS+N_AUDIO_ITEM+ASP_INDEX_NUM
EXT volatile PASSWORD_SETTING Password_Setting_EEP @(EEP_ASP_ADDRESS);
EXT volatile SETTING_FLAG Setting_Flag_EEP @(EEP_ASP_ADDRESS+1);
#if 0
EXT volatile uchar nScreenPicture_EEP[SCREEN_PIC_NUM] @(EEP_ASP_ADDRESS+1);//5 byte
#endif
EXT volatile uchar Source_L_EEP[6] @(EEP_ASP_ADDRESS+2);//6 byte
EXT volatile uchar Radio_Area_EEP @(EEP_ASP_ADDRESS+8);
EXT volatile RDS_FLAG RDS_Flag_EEP @(EEP_ASP_ADDRESS+9);
EXT volatile uchar MainVolLevel_EEP[2] @(EEP_ASP_ADDRESS+10);
EXT volatile _OSD_LANGUAGE_INDEX  Navi_Osd_Language_EEP @(EEP_ASP_ADDRESS+12);
#define SETTING_BTYE_NUM EEP_ASP_ADDRESS+13-EEP_SETTING_ADDRESS
EXT volatile uchar SettingChkSum @(EEP_SETTING_ADDRESS+SETTING_BTYE_NUM);

#define EEP_RADIO_ADDRESS (FLASH_DATA_START_PHYSICAL_ADDRESS+FLASH_BLOCK_SIZE)
EXT volatile uchar CurrentBand_EEP @(EEP_RADIO_ADDRESS);
EXT volatile u16 RadioFreq_EEP @(EEP_RADIO_ADDRESS+1);
EXT volatile uchar CurrentPreset_EEP @(EEP_RADIO_ADDRESS+3);
EXT volatile u16 BandFreq_EEP[FM_BAND_NUM+AM_BAND_NUM] @(EEP_RADIO_ADDRESS+4);
#define EEP_RADIOMEMFREQ_ADDRESS (EEP_RADIO_ADDRESS+(FM_BAND_NUM+AM_BAND_NUM)*2+4)
EXT volatile u16 MemFreq_EEP[FM_BAND_NUM+AM_BAND_NUM][MAX_PRESET_NUM] @(EEP_RADIOMEMFREQ_ADDRESS);
#define RADIO_BTYE_NUM ((FM_BAND_NUM+AM_BAND_NUM)*MAX_PRESET_NUM*2+EEP_RADIOMEMFREQ_ADDRESS-EEP_RADIO_ADDRESS)
EXT volatile uchar RadioChkSum @(EEP_RADIO_ADDRESS+RADIO_BTYE_NUM);

#define EEP_WHLKEY_ADDRESS 0x4100
EXT uchar WheelKey_Tab[2][10][3] @(EEP_WHLKEY_ADDRESS);
#define WHEELKEY_BYTE_NUM   60
EXT uchar WheelKeyChkSum @(EEP_WHLKEY_ADDRESS+WHEELKEY_BYTE_NUM);

typedef enum
{
    FLASH_CODE=1,
    FLASH_DATA=2
}FlashType;

void EepromInit(void);
void EepromInnerWrite(u8 *DesMemery,u8 *SrcMemery,u8 NumOfByte);
void EepromInnerRead(u8 *DesMemery,u8 *SrcMemery,u8 NumOfByte);
void FlashWaitForEepromOperation(void);
void FlashSetProgrammingTime(FLASH_ProgramTime_Typedef ProgTime);
void FlashUnlock(FlashType MemType);
void FlashLock(FlashType MemType);
void EepromWriteByte(u8 *Address,u8 Data);
void EepromWriteWord(u32 *Address,u32 Data32);
void EepromPageWriteStart(void);
bool ReadSettingEeprom(void);
void WriteSettingEeprom(void);
void WriteRadioEeprom(void);
void WriteRadioSelectEeprom(void);
bool ReadRadioEeprom(void);
void CalculateWheelKeyChkSum(void);
bool CheckWheelKeyChkSum(void);

#endif

#endif
